package com.example.javajetpacktest.utils;

import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;
import java.util.List;
import java.util.Random;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * @author shili Last Modifiy : 2010-07-02
 * modify by shili at 2018-10-2 修改了 addDay 方法的bug
 */
public class DateTime {

    /**
     * 获取当前时间 零点的时间
     *
     * @return
     */
    public static Date getZeroDateInDay() {
        return getZeroDateInDay(null);
    }

    /**
     * 获取指定时间的 零点时间
     *
     * @return
     */
    public static Date getZeroDateInDay(Date date) {
        if (date == null) {
            date = new Date();
        }

        SimpleDateFormat format = new SimpleDateFormat("yyyy-M-d");

        try {
            return format.parse(getYear(date) + "-" + getMonth(date) + "-" + getDay(date));
        } catch (ParseException e) {
            e.printStackTrace();
            return null;
        }
    }

    /**
     * 获取当前时间 当月第一天的零点时间
     *
     * @return
     */
    public static Date getZeroDateInFirstDayOfMonth() {
        return getZeroDateInFirstDayOfMonth(null);
    }

    /**
     * 获取指定时间 当月第一天的零点时间
     *
     * @return
     */
    public static Date getZeroDateInFirstDayOfMonth(Date date) {
        if (date == null) {
            date = new Date();
        }

        SimpleDateFormat format = new SimpleDateFormat("yyyy-M-d");

        try {
            return format.parse(getYear(date) + "-" + getMonth(date) + "-1");
        } catch (ParseException e) {
            e.printStackTrace();
            return null;
        }

    }


    /**
     * 获取当前时间 下个月第一天的零点时间
     *
     * @return
     */
    public static Date getZeroDateInFirstDayOfNextMonth() {
        return getZeroDateInFirstDayOfNextMonth(null);
    }

    /**
     * 获取指定时间 下个月第一天的零点时间
     *
     * @return
     */
    public static Date getZeroDateInFirstDayOfNextMonth(Date date) {
        if (date == null) {
            date = new Date();
        }

        SimpleDateFormat format = new SimpleDateFormat("yyyy-M-d");

        int month = getMonth(date);
        int nextMonth = month == 12 ? 1 : month + 1;
        int nextDay = month == 12 ? getYear(date) + 1 : getYear(date);
        try {
            return format.parse(nextDay + "-" + nextMonth + "-1");
        } catch (ParseException e) {
            e.printStackTrace();
            return null;
        }

    }

    /**
     * 通过给定的 小时 分钟 和 秒数 返回 当天的时间
     * @param hour
     * @param minute
     * @param second
     * @return
     */
    public static Long getCurrentDayTimerByTime(int hour, int minute, int second) {
        String s = getStrDate(Format.yymmdd);
        Date date = getDate(Format.sfull,getStrDate(Format.yyyymd)+" "+hour+":"+minute+":"+second);
        return date.getTime();
    }

    public enum Format {
        full, md, mmdd, sfull, yymd, yymmdd, yyyymd, yyyymmdd, wxfull
    }


    /**
     * 判断当前字符串是否为标准时间类型  包含 yyyy-mm-dd hh-MM-SS 和 yyyy-m-d h-M-S
     *
     * @param date 时间
     * @return
     */
    public static boolean checkDate(String date) {
        if (date == null || date.length() == 0) {
            return false;
        }
        String format = "((19|20)[0-9]{2})-(0?[1-9]|1[012])-(0?[1-9]|[12][0-9]|3[01]) "
                + "([01]?[0-9]|2[0-3]):[0-5][0-9]:[0-5][0-9]";
        Pattern pattern = Pattern.compile(format);
        Matcher matcher = pattern.matcher(date);
        return matcher.matches();
    }

    /**
     * 验证时间格式是否正确
     *
     * @param date 时间
     * @param f    时间格式 例如:yyyy-MM-dd HH:mm:ss
     * @return
     */
    public static boolean checkDate(String date, Format f) {
        SimpleDateFormat df = new SimpleDateFormat(getDateTimeFormat(f));
        Date d = null;
        try {
            d = df.parse(date);
        } catch (Exception e) {
            return false;
        }
        String s1 = df.format(d);
        return date.equals(s1);
    }

    /**
     * 返回指定格式的当前时间
     * <p>
     * 时间日期格式
     *
     * @return 一个Date类型时间
     */
    public static Date getDate() {
        return getDate(null);
    }

    /**
     * 返回指定格式的当前时间
     *
     * @param f 时间日期格式
     * @return 一个Date类型时间
     */
    public static Date getDate(Format f) {
        if (f == null) {
            return new Date();
        } else {
            SimpleDateFormat df = new SimpleDateFormat(getDateTimeFormat(f));
            Date d = new Date();
            try {
                d = df.parse(d.toString());
            } catch (Exception e) {
            }
            return d;
        }
    }

    /**
     * 给出一个字符串 返回时间类型数据
     *
     * @param f         枚举时间格式
     * @param _dateTime 时间字符串
     * @return 一个时间日期类型;
     */
    public static Date getDate(Format f, String _dateTime) {
        Date temp_d;
        SimpleDateFormat df = new SimpleDateFormat(getDateTimeFormat(f));
        try {
            temp_d = df.parse(_dateTime);
        } catch (ParseException e) {
            e.printStackTrace();
            temp_d = null;
        }
        return temp_d;
    }

    /**
     * 对枚举类型进行格式转换
     *
     * @param f
     * @return
     */
    private static String getDateTimeFormat(Format f) {
        if (f.equals(Format.full)) {
            return "yyyy-MM-dd HH:mm:ss";
        }

        if (f.equals(Format.wxfull)) {
            return "yyyyMMddHHmmss";
        }

        if (f.equals(Format.sfull)) {
            return "yyyy-M-d H:m:s";
        }

        if (f.equals(Format.yyyymmdd)) {
            return "yyyy-MM-dd";
        }

        if (f.equals(Format.yyyymd)) {
            return "yyyy-M-d";
        }

        if (f.equals(Format.yymmdd)) {
            return "yy-MM-dd";
        }

        if (f.equals(Format.yymd)) {
            return "yy-M-d";
        }

        if (f.equals(Format.mmdd)) {
            return "MM-dd";
        }

        if (f.equals(Format.md)) {
            return "M-d";
        }

        return "";
    }

    /**
     * 获取当前时间的日期
     *
     * @return
     */
    public static int getDay() {
        Calendar c = Calendar.getInstance();
        return c.get(Calendar.DAY_OF_MONTH);
    }

    /**
     * 获取一个时间日期的日期
     *
     * @param date 一个时间
     * @return
     */
    public static int getDay(Date date) {

        Calendar c = Calendar.getInstance();
        c.setTime(date);
        return c.get(Calendar.DAY_OF_MONTH);
    }

    /**
     * 通过年和月来获取当月有多少天
     *
     * @param _year  给定的年份四位 如2002
     * @param _month 给定的年份 如3
     * @return 返回一个整形
     */
    public static int getDayCountByMonth(int _year, int _month) {
        int monthDay[] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
        if ((_year % 4 == 0 && _year % 100 != 0) || _year % 400 == 0)
            monthDay[1]++;
        return monthDay[_month - 1];
    }

    /**
     * 获取当前时间的小时数
     *
     * @return 小时数
     */
    public static int getHour() {
        Calendar c = Calendar.getInstance();
        // int a = c.get(Calendar.HOUR_OF_DAY);
        return c.get(Calendar.HOUR_OF_DAY);
    }

    /**
     * 获取一个时间日期的小时数
     *
     * @param date 一个时间
     * @return 小时数
     */
    public static int getHour(Date date) {

        Calendar c = Calendar.getInstance();
        c.setTime(date);
        return c.get(Calendar.HOUR_OF_DAY);
    }

    /**
     * 获取当前时间的豪秒数
     *
     * @return 豪秒数
     */
    public static int getMillisecond() {
        Calendar c = Calendar.getInstance();
        // int a = c.get(Calendar.HOUR_OF_DAY);
        return c.get(Calendar.MILLISECOND);
    }

    /**
     * 获取当前时间的分钟数
     *
     * @return 分钟数
     */
    public static int getMinute() {
        Calendar c = Calendar.getInstance();
        // int a = c.get(Calendar.HOUR_OF_DAY);
        return c.get(Calendar.MINUTE);
    }

    /**
     * 获取当前时间的月份
     *
     * @return
     */
    public static int getMonth() {
        Calendar c = Calendar.getInstance();
        c.setTime(getDate(Format.full));
        return c.get(Calendar.MONTH) + 1;
    }

    /**
     * 获取一个时间日期的月份
     *
     * @param date 一个时间
     * @return
     */
    public static int getMonth(Date date) {

        Calendar c = Calendar.getInstance();
        c.setTime(date);
        return c.get(Calendar.MONTH) + 1;
    }

    /**
     * 获取当前时间的秒数
     *
     * @return 秒数
     */
    public static int getSecond() {
        Calendar c = Calendar.getInstance();
        // int a = c.get(Calendar.HOUR_OF_DAY);
        return c.get(Calendar.SECOND);
    }

    /**
     * 获取当前日期 是本几年中的第几周
     *
     * @return
     */
    public static int getWeekOfYear() {
        return getWeekOfYear(new Date());
    }

    /**
     * 获取给定的日期 是本几年中的第几周
     *
     * @return
     */
    public static int getWeekOfYear(Date date) {
        Calendar calendar = Calendar.getInstance();
        calendar.setFirstDayOfWeek(Calendar.MONDAY);
        calendar.setTime(date);

        return calendar.get(Calendar.WEEK_OF_YEAR);
    }

    /**
     * 返回一个给定的[时间]的字符串
     *
     * @param f 时间格式 例如 "HH:mm:ss"
     * @return 时间字符串 例:2010-03-01 1-2-3
     */
    public static String getStrDate(String f) {
        SimpleDateFormat df = new SimpleDateFormat(f);
        return df.format(getDate());
    }

    /**
     * 返回一个给定的[时间]的字符串
     *
     * @param date 时间
     * @param f 时间格式 例如 "HH:mm:ss"
     * @return 时间字符串 例:2010-03-01 1-2-3
     */
    public static String getStrDate(Date date, String f) {
        SimpleDateFormat df = new SimpleDateFormat(f);
        return df.format(getDate());
    }


    /**
     * 返回一个给定的[时间]的字符串
     *
     * @param f .Format.full 枚举时间格式
     * @return 时间字符串 例:2010-03-01 1-2-3
     */
    public static String getStrDate(Format f) {
        SimpleDateFormat df = new SimpleDateFormat(getDateTimeFormat(f));
        return df.format(getDate());
    }

    /**
     * 返回一个给定的[时间]的字符串
     *
     * @param f         .Format.full 枚举时间格式
     * @param _datetime 相关时间
     * @return 时间字符串 例:2010-03-01
     */
    public static String getStrDate(Format f, Date _datetime) {
        SimpleDateFormat df = new SimpleDateFormat(getDateTimeFormat(f));
        return df.format(_datetime);
    }

    /**
     * 返回一个给定的[时间]的字符串
     *
     * @param f         .Format.full 输出的格式
     * @param sourcef   .Format.full 输入的格式
     * @param _datetime 相关时间字符串
     * @return 时间字符串 如果转换出错 则返回""空字符串
     */
    public static String getStrDate(Format f, Format sourcef, String _datetime) {
        SimpleDateFormat df = new SimpleDateFormat(getDateTimeFormat(sourcef));
        SimpleDateFormat df2 = new SimpleDateFormat(getDateTimeFormat(f));
        String _dateTime = "";

        Date _date = null;
        _date = getDate(sourcef, _datetime);

        return df2.format(_date);
    }

    /**
     * 返回一个给定的[时间间隔]的字符串
     * <p>
     * .Format.full 枚举时间格式
     *
     * @param Interval 间隔毫秒数
     * @return 时间字符串 例:2010-03-01
     */
    public static String getStrDate(Format f, int Interval) {
        Calendar c = Calendar.getInstance();
        c.add(Calendar.SECOND, Interval);
        SimpleDateFormat df = new SimpleDateFormat(getDateTimeFormat(f));
        return df.format(c.getTime());
    }

    /**
     * 返回从 时间d1 到 时间d2 相差的秒数
     *
     * @param d1 开始时间
     * @param d2 结束时间
     * @return
     */
    public static int getTimeDiff(Date d1, Date d2) {
        long _diff = d2.getTime() - d1.getTime();
        int _temp = Math.round(_diff / 1000);
        return _temp;
    }

    /**
     * 返回从 时间d1 到 时间d2 相差的秒数
     *
     * @param d1 开始时间字符串 2010-01-01 01:02:33
     * @param d2 结束时间字符串 2010-02-01 01:02:33
     * @return 返回秒数 格式有错误则返回-1;
     */
    public static int getTimeDiff(String d1, String d2) {
        int _temp = 0;
        try {
            SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
            Date _d1 = df.parse(d1);
            Date _d2 = df.parse(d2);
            long _diff = _d2.getTime() - _d1.getTime();
            _temp = Math.round(_diff / 1000);
        } catch (ParseException e) {
            _temp = -1;
            e.printStackTrace();

        }
        return _temp;
    }

    /**
     * 获取当前时间的年份
     *
     * @return
     */
    public static int getYear() {
        Calendar c = Calendar.getInstance();
        c.setTime(getDate(Format.full));
        return c.get(Calendar.YEAR);
    }

    /**
     * 获取一个给定的时间日期的年份
     *
     * @param date 一个时间
     * @return
     */
    public static int getYear(Date date) {

        Calendar c = Calendar.getInstance();
        c.setTime(date);
        return c.get(Calendar.YEAR);
    }

    /**
     * 获得一个f格式的当前时间的字符串
     *
     * @param f
     * @return
     */
    public static String getNowDate(Format f) {
        SimpleDateFormat df = new SimpleDateFormat(getDateTimeFormat(f));
        return df.format(getDate(f));
    }

    /**
     * // string类型转换为date类型
     * // strTime要转换的string类型的时间，formatType要转换的格式yyyy-MM-dd HH:mm:ss//yyyy年MM月dd日
     * // HH时mm分ss秒，
     * // strTime的时间格式必须要与formatType的时间格式相同
     *
     * @param strTime
     * @param f
     * @return
     * @throws ParseException
     */
    public static Date stringToDate(String strTime, Format f) throws ParseException {
        SimpleDateFormat formatter = new SimpleDateFormat(getDateTimeFormat(f));
        Date date = null;
        date = formatter.parse(strTime);
        return date;
    }

    //

    /**
     * String类型转换为long类型
     *
     * @param strTime 时间字符串
     * @param f       时间类型格式
     * @return
     */
    public static long stringToLong(String strTime, Format f) throws ParseException {
        Date date = stringToDate(strTime, f); // String类型转成date类型
        if (date == null) {
            return 0;
        } else {
            long currentTime = dateToLong(date); // date类型转成long类型
            return currentTime;
        }
    }

    //

    /**
     * date类型转换为long类型
     *
     * @param date 日期型时间类型
     * @return
     */
    public static long dateToLong(Date date) {
        return date.getTime();
    }


// 	//获得本周一 00:00:00
// 	public  static Date getMondayDayOfWeek(Date date){
//   	 Calendar calendar = Calendar.getInstance();
//	        calendar.setTime(date);
//	        calendar.set(Calendar.HOUR_OF_DAY, 0);
//	        calendar.set(Calendar.MINUTE, 0);
//	        calendar.set(Calendar.SECOND, 0);
//	        calendar.set(Calendar.MILLISECOND, 0);
//	        calendar.setFirstDayOfWeek(Calendar.MONDAY);
////	        calendar.set(Calendar.DAY_OF_WEEK,Calendar.MONDAY);
//
//	        int week = calendar.get(Calendar.DAY_OF_WEEK);
//	        calendar.add(Calendar.DAY_OF_WEEK, 1 - week);
//			return calendar.getTime();
//
//
//   }
// 	//获得本周天 23:59:59
//   public  static Date getSunDayOfWeek(Date date){
//   	 Calendar calendar = Calendar.getInstance();
//	        calendar.setTime(date);
//	        calendar.set(Calendar.HOUR_OF_DAY, 23);
//	        calendar.set(Calendar.MINUTE, 59);
//	        calendar.set(Calendar.SECOND, 59);
//	        calendar.set(Calendar.MILLISECOND,0);
//	        calendar.setFirstDayOfWeek(Calendar.MONDAY);
//	        calendar.set(Calendar.DAY_OF_WEEK,Calendar.SUNDAY);
//
//	        return calendar.getTime();
//
//   }

    public static String longToString(long millis, Format f) {
        Calendar cal = Calendar.getInstance();
        cal.setTimeInMillis(millis);
        SimpleDateFormat df = new SimpleDateFormat(getDateTimeFormat(f));
        return df.format(cal.getTime());
    }


    /**
     * 得到本周周一
     *
     * @return yyyy-MM-dd
     */
    public static Date getMondayDayOfWeek() {
        Calendar c = Calendar.getInstance();
        int dayofweek = c.get(Calendar.DAY_OF_WEEK) - 1;
        if (dayofweek == 0)
            dayofweek = 7;
        c.add(Calendar.DATE, -dayofweek + 1);
        c.set(Calendar.HOUR_OF_DAY, 0);
        c.set(Calendar.MINUTE, 0);
        c.set(Calendar.SECOND, 0);
        c.set(Calendar.MILLISECOND, 0);
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        return c.getTime();
    }

    /**
     * 得到本周周日
     *
     * @return yyyy-MM-dd
     */
    public static Date getSunDayOfWeek() {
        Calendar c = Calendar.getInstance();
        int dayofweek = c.get(Calendar.DAY_OF_WEEK) - 1;
        if (dayofweek == 0)
            dayofweek = 7;
        c.add(Calendar.DATE, -dayofweek + 7);
        c.set(Calendar.HOUR_OF_DAY, 23);
        c.set(Calendar.MINUTE, 59);
        c.set(Calendar.SECOND, 59);
        c.set(Calendar.MILLISECOND, 0);
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        return c.getTime();
    }

    /**
     * 得到一个字符串 时间固定 + 随机
     *
     * @return yyyy-MM-dd hh-mm-ss
     */
    public static String getFullStringByTime() {
        String format = "yyyyMMddHHmmss";
        Date date = new Date();
        date.setTime(System.currentTimeMillis());
        SimpleDateFormat sdf = new SimpleDateFormat(format);
        return sdf.format(date) + new Random().nextInt(1000);
    }

    /**
     * 将时间转换类型截取字段
     */
    public static String subDate(String date) {
        try {
            Date currentDate = DateTime.stringToDate(date, Format.full);
            String times = DateTime.getStrDate(Format.yymmdd, currentDate);
            String[] dateArray = times.split("-");
            String dateStr = dateArray[1] + "/" + dateArray[2] + "/" + dateArray[0];
            return dateStr;
        } catch (ParseException e) {
            e.printStackTrace();
        }

        return null;
    }

    /**
     * 时间显示年月日
     */
    public static String showymdDate(String date) {
        if (date == null) {
            return "";
        }
        try {
            Date currentDate = DateTime.stringToDate(date, Format.full);
            String times = DateTime.getStrDate(Format.yyyymmdd, currentDate);
            return times;
        } catch (ParseException e) {
            e.printStackTrace();
        }

        return null;
    }

    /**
     * 判断是不是今天
     *
     * @param time
     * @return
     */
    public static boolean isNow(String time) {
        Date date = getDate(Format.full, time);
        //当前时间
        Date now = new Date();
        SimpleDateFormat sf = new SimpleDateFormat("yyyyMMdd");
        //获取今天的日期
        String nowDay = sf.format(now);


        //对比的时间
        String day = sf.format(date);

        return day.equals(nowDay);
    }

    /**
     * 判断是不是昨天
     *
     * @param time
     * @return
     */
    public static boolean isYesterday(String time) {
        Date date = getDate(Format.full, time);
        //当前时间
        Date now = new Date();
        SimpleDateFormat sf = new SimpleDateFormat("yyyyMMdd");
        //获取昨天的日期
        String yesterday = sf.format(new Date(now.getTime() - 86400000L));
        //对比的时间
        String day = sf.format(date);

        return day.equals(yesterday);
    }

    /**
     * 在指定日期上加上指定天数
     *
     * @param date
     * @param i    天数
     * @return
     */
    public static synchronized Date addDay(Date date, int i) {
        Calendar c = Calendar.getInstance();
        c.setTime(date);
        c.add(Calendar.DATE, i);
        return c.getTime();
    }

    /**
     * 在指定日期上加上指定毫秒数
     *
     * @param date
     * @param i    毫秒
     * @return
     */
    public static Date addMilliSecond(Date date, int i) {
        Calendar c = Calendar.getInstance();
        c.setTime(date);
        c.add(Calendar.MILLISECOND, i);
        return c.getTime();
    }


    /**
     * 获取当前星期几
     *
     * @param date
     * @return
     */
    public static String getWeek(Date date) {
        String[] weeks = {"星期日", "星期一", "星期二", "星期三", "星期四", "星期五", "星期六"};
        Calendar cal = Calendar.getInstance();
        cal.setTime(date);
        int week_index = cal.get(Calendar.DAY_OF_WEEK) - 1;
        if (week_index < 0) {
            week_index = 0;
        }
        System.out.println(weeks[week_index]);
        return weeks[week_index];
    }

    /**
     * 获取一周开始到结束的list集合
     *
     * @param dBegin
     * @param dEnd
     * @return
     */
    public static List<Date> findDates(Date dBegin, Date dEnd) {
        List lDate = new ArrayList();
        lDate.add(dBegin);
        Calendar calBegin = Calendar.getInstance();
        // 使用给定的 Date 设置此 Calendar 的时间
        calBegin.setTime(dBegin);
        Calendar calEnd = Calendar.getInstance();
        // 使用给定的 Date 设置此 Calendar 的时间
        calEnd.setTime(dEnd);
        // 测试此日期是否在指定日期之后
        while (dEnd.after(calBegin.getTime())) {
            // 根据日历的规则，为给定的日历字段添加或减去指定的时间量
            calBegin.add(Calendar.DAY_OF_MONTH, 1);
            lDate.add(calBegin.getTime());
        }
        return lDate;
    }

    /**
     * 判断两个时间是否在同一周
     *
     * @param date1
     * @param date2
     * @return
     */
    public static boolean isSameDate(String date1, String date2) {
        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
        Date d1 = null;
        Date d2 = null;
        try {
            d1 = format.parse(date1);
            d2 = format.parse(date2);
        } catch (Exception e) {
            e.printStackTrace();
        }
        Calendar cal1 = Calendar.getInstance();
        Calendar cal2 = Calendar.getInstance();
        cal1.setFirstDayOfWeek(Calendar.MONDAY);//西方周日为一周的第一天，咱得将周一设为一周第一天
        cal2.setFirstDayOfWeek(Calendar.MONDAY);
        cal1.setTime(d1);
        cal2.setTime(d2);
        int subYear = cal1.get(Calendar.YEAR) - cal2.get(Calendar.YEAR);
        if (subYear == 0)// subYear==0,说明是同一年
        {
            return cal1.get(Calendar.WEEK_OF_YEAR) == cal2.get(Calendar.WEEK_OF_YEAR);
        } else if (subYear == 1 && cal2.get(Calendar.MONTH) == 11) //subYear==1,说明cal比cal2大一年;java的一月用"0"标识，那么12月用"11"
        {
            return cal1.get(Calendar.WEEK_OF_YEAR) == cal2.get(Calendar.WEEK_OF_YEAR);
        } else if (subYear == -1 && cal1.get(Calendar.MONTH) == 11)//subYear==-1,说明cal比cal2小一年
        {
            return cal1.get(Calendar.WEEK_OF_YEAR) == cal2.get(Calendar.WEEK_OF_YEAR);
        }
        return false;
    }

    /**
     * 获取一个时间段的集合
     *
     * @param startTime
     * @param endTime
     * @param format
     * @return
     */
    public static List<String> getDays(String startTime, String endTime, String format) {

        // 返回的日期集合
        List<String> days = new ArrayList<String>();

        DateFormat dateFormat = new SimpleDateFormat(format);
        try {
            Date start = dateFormat.parse(startTime);
            Date end = dateFormat.parse(endTime);

            Calendar tempStart = Calendar.getInstance();
            tempStart.setTime(start);

            Calendar tempEnd = Calendar.getInstance();
            tempEnd.setTime(end);
            tempEnd.add(Calendar.DATE, +1);
            while (tempStart.before(tempEnd)) {
                days.add(dateFormat.format(tempStart.getTime()));
                tempStart.add(Calendar.DAY_OF_YEAR, 1);
            }

        } catch (ParseException e) {
            e.printStackTrace();
        }
        return days;
    }


    public static void main(String[] args) {
//        SimpleDateFormat sf = new SimpleDateFormat("yyyyMMdd");
//        Date date = sf.parse("20201213");
//        System.out.println(getStrDate(Format.full, getZeroDateInFirstDayOfMonth()));
//        System.out.println(getStrDate(Format.full, getZeroDateInFirstDayOfNextMonth(date)));
//        System.out.println(DateTime.getStrDate("HH:mm:ss"));

        System.out.println(new Date(getCurrentDayTimerByTime(13,10,31)));
    }


    /**
     * 获取某一年的某一周的周日日期
     *
     * @param year
     * @param weekNo
     * @return
     */
    public static String getEndDayOfWeekNo(int year, int weekNo) {
        Calendar cal = getCalendarFormYear(year);
        cal.set(Calendar.WEEK_OF_YEAR, weekNo);
        cal.add(Calendar.DAY_OF_WEEK, 6);
        return cal.get(Calendar.YEAR) + "-" + (cal.get(Calendar.MONTH) + 1) + "-" +
                cal.get(Calendar.DAY_OF_MONTH);
    }


    /**
     * 获取某一年的某一周的周一日期
     *
     * @param year
     * @param weekNo
     * @return
     */
    public static String getStartDayOfWeekNo(int year, int weekNo) {
        Calendar cal = getCalendarFormYear(year);
        cal.set(Calendar.WEEK_OF_YEAR, weekNo);
        return cal.get(Calendar.YEAR) + "-" + (cal.get(Calendar.MONTH) + 1) + "-" +
                cal.get(Calendar.DAY_OF_MONTH);

    }

    /**
     * 得到某年某周的第一天
     *
     * @param year（yyyy）
     * @param week
     * @return String(yyyy-MM-dd)
     */
    public static String getFirstDayOfWeek(Integer year, Integer week) {
        Calendar c = new GregorianCalendar();
        c.set(Calendar.YEAR, year);
        c.set (Calendar.MONTH, Calendar.JANUARY);
        c.set(Calendar.DATE, 1);

        Calendar cal = (GregorianCalendar) c.clone();
        cal.add(Calendar.DATE, (week-1) * 7);

        return getFirstDayOfWeek(cal.getTime());
    }


    /**
     * 取得指定日期所在周的第一天
     *
     * @param date
     * @return String(yyyy-MM-dd)
     */
    public static String getFirstDayOfWeek(Date date) {
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        Calendar c = new GregorianCalendar();
        c.setFirstDayOfWeek(Calendar.MONDAY);
        c.setTime(date);
        c.set(Calendar.DAY_OF_WEEK, c.getFirstDayOfWeek()); // Monday
        return sdf.format(c.getTime());
    }

    /**
     * 得到某年某周的最后一天
     *
     * @param year(yyyy)
     * @param week
     * @return String(yyyy-MM-dd)
     */
    public static String getLastDayOfWeek(Integer year, Integer week) {
        Calendar c = new GregorianCalendar();
        c.set(Calendar.YEAR, year);
        c.set(Calendar.MONTH, Calendar.JANUARY);
        c.set(Calendar.DATE, 1);

        Calendar cal = (GregorianCalendar) c.clone();
        cal.add(Calendar.DATE , (week-1) * 7);

        return getLastDayOfWeek(cal.getTime());
    }

    /**
     * 取得指定日期所在周的最后一天
     *
     * @param date
     * @return String(yyyy-MM-dd)
     */
    public static String getLastDayOfWeek(Date date) {
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        Calendar c = new GregorianCalendar();
        c.setFirstDayOfWeek(Calendar.MONDAY);
        c.setTime(date);
        c.set(Calendar.DAY_OF_WEEK, c.getFirstDayOfWeek() + 6); // Sunday
        return sdf.format(c.getTime());
    }


    /**
     * 获取这一年的日历
     *
     * @param year
     * @return
     */
    private static Calendar getCalendarFormYear(int year) {
        Calendar cal = Calendar.getInstance();
        cal.set(Calendar.DAY_OF_WEEK, Calendar.MONDAY);
        cal.set(Calendar.YEAR, year);
        return cal;
    }

}